<?php
/*
 * @Author: zwx
 * @Date: 2024-06-08 21:28:18
 * @LastEditors: zwx
 * @LastEditTime: 2024-06-18 20:57:14
 * @Description: 
 */

namespace app\apiadmin\service\behavior;

use app\apiadmin\model\behavior\ControlMongo;

class ControlService extends ControlMongo
{

    /**
     * 邀请记录
     *
     * */
    public static function invitationList($param)
    {
        $param['query'] = array_merge($param['query'] ?? [], ['del' => 0, 'status' => 1]);
        $total = parent::total($param['query'] ?? []);
        $list = parent::list($param['query'] ?? [], $param['options'] ?? []);
        return [
            'total' => $total,
            'list' => $list,
        ];
    }

    /**
     * 签到记录
     *
     * */
    public static function singList($param)
    {
        $param['query'] = array_merge($param['query'] ?? [], ['del' => 0, 'status' => 2]);
        $total = parent::total($param['query'] ?? []);
        $list = parent::list($param['query'] ?? [], $param['options'] ?? []);
        return [
            'total' => $total,
            'list' => $list,
        ];
    }

    /**
     * 删除记录
     *
     * */
    public static function delId(string $id = null): bool
    {
        if (empty($id)) {
            return false;
        }
        return parent::del($id);
    }

    /**
     * 更新或插入记录
     *
     * */
    public static function addOrEdit($param)
    {
        if (empty($param)) {
            return false;
        }
        if (!empty($param['user'])) {
            $param['user_id'] = $param['user']['id'];
            $param['user_name'] = $param['user']['nickname'];
            $param['user_avatar'] = $param['user']['avatar'] ?? $param['user']['wx_avatarurl'];
            $param['user_content'] = $param['user']['msg'];
        }
        $data['query'] = [
            'liveId' => $param['liveId'],  // 直播ID
            // 'user_id' => $param['user_id'],  // 用户ID
            //'user_name' => $param['user_name'],  // 用户昵称
            //'wx_avatarurl' => $param['user_avatar'],  // 用户头像
            //'content' => $param['user_content'],  // 用户评论内容
            // 'operator_account' => $param['operator_account'],  // 操作人ID
            //'operator_name' => $param['operator_name'],  // 操作人名称
            // 'operator_type' => $param['operator_type'],  // 操作类型
            //'operator_time' => $param['operator_time'],  // 操作时间
            'del' => 0,
        ];
        $data['set'] = [
            '$set' => [
                'operator_account' => $param['operator_account'],  // 操作人ID
                'operator_type' => $param['operator_type'],  // 操作类型
                'operator_name' => $param['operator_name'],
                'operator_role' => $param['operator_role'],
                'operator_time' => time(),
            ]
        ];
        $data['options'] = ['upsert' => true];
        return parent::addOrEdit($data);
    }


}
